#include <bits/stdc++.h>    
using namespace std;
int tong[(int)1e6+5];
int n,c,t;
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    while(t--){
        memset(tong,0,sizeof tong);
        cin >> n;
        for(int i = 1;i <= n;i++){
            cin >> c;
            tong[c]++;
        }
        long long ans=0;
        for(int i = 1;i <= 1e6;i++)ans+=((tong[i]>1?((max(tong[i]-1,0))):0)*i);
        cout << ans << endl;
    }
    return 0;
}
// abcabc
// ABcABc